<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>完善企业资料</title>

	<link href="<?php echo G_STATIC_URL; ?>/css/default/data.css" rel="stylesheet" />
	<link href="<?php echo G_STATIC_URL; ?>/css/default/index.css" rel="stylesheet" />

	<link href="<?php echo G_STATIC_URL; ?>/css/default/index.css" rel="stylesheet" />
	<link href="<?php echo G_STATIC_URL; ?>/css/default/global.css?v=1" rel="stylesheet" />

	<link rel="stylesheet" href="<?php echo G_STATIC_URL; ?>/css/bootstrap.min.css">
	<link rel="stylesheet" href="<?php echo G_STATIC_URL; ?>/css/font-awesome.min.css">
	<link rel="stylesheet" href="<?php echo G_STATIC_URL; ?>/css/main.css">
	<link rel="stylesheet" href="<?php echo G_STATIC_URL; ?>/css/animate.css">
	<link rel="stylesheet" href="<?php echo G_STATIC_URL; ?>/css/responsive.css">
	<script src="<?php echo G_STATIC_URL; ?>/js/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="<?php echo G_STATIC_URL; ?>/js/distpicker.data.js"></script>
	<script type="text/javascript" src="<?php echo G_STATIC_URL; ?>/js/distpicker.js"></script>
	<script type="text/javascript" src="<?php echo G_STATIC_URL; ?>/js/ajaxfileupload.js"></script>

</head>

<body style="background-color: #f2f6fa;">
<header>
	<div class="container">
		<div class="row">
			<div class="col-md-3 col-xs-6 col-sm-3">
				<a href="/?/explore/index/" class="logo">
					<img src="<?php echo G_STATIC_URL; ?>/css/images/logo.png" alt="">
				</a>
			</div>


		</div>
	</div>
</header>

<br/>
<br/>
<br/>

	<div class="content">
		<div class="fill_data">
			<div class="fill_title">
				完善企业资料
			</div>
			<div class="fill_ct">
				<div class="select_ct fill_main">
					<span class="left_nm">所在行业：</span>
					<div class="select_city">

						<select name="pro" id="job">
							<?php foreach ($this->list AS $key => $val) { ?>

							<option value="<?php echo $val['id']; ?>"><?php echo $val['name']; ?></option>
							<?php } ?>

						</select>



					</div>
				</div>
				<div class="select_ct fill_main">
					<span class="left_nm">所在城市：</span>
					<div class="select_city" id="select_city">
						<select name="pro" id="selectpro">
						</select>
						<select name="city" id="selectcity">
						</select>

					</div>
				</div>
				<div class="upload_idimg fill_main">
					<span class="left_nm">营业执照证件照片：</span>
					<div class="upload_ct">
						<div class="upload_tt">
							正面<span>（格式:3M以下的jpg，png或bmp）</span>
						</div>
						<div class="file_up">
							<span class="left_up"><img id="right_img" src="<?php echo G_STATIC_URL; ?>/common/addid.png" alt=""><input type="file"  id="up_right"  onchange="uploadeImage(this,'0');return false;"></span>
							<span class="right_idimg"><img src="<?php echo G_STATIC_URL; ?>/common/company_img.png" alt=""></span>
						</div>
					</div>
				</div>

			</div>
			<div class="complete_btn">
				<span>完成</span>
			</div>
		</div>
	</div>

</body>
</html>
<script type="application/javascript">

	var right_img = "";
	$(function () {


		$('#select_city').distpicker({
			autoSelect: false
		});

		$('.complete_btn').click(function () {

			var job  = $('#job').val();
			var selectpro  = $('#selectpro').val();
			var selectcity  = $('#selectcity').val();

			if(job== ''){
				alert('请选择类型');
				return false;
			}
			if(selectpro== ''){
				alert('请选择省份');
				return false;
			}
			if(selectcity== ''){
				alert('请选择城市');
				return false;
			}
			if(right_img== ''){
				alert('请选择上传证件');
				return false;
			}

			$.post('/?/account/ajax/update_org/',{"cat":job,"province":selectpro,"city":selectcity,"url":right_img},function (result) {

				if(result.errno == 1){

					window.location.href="/?/explore/index/";
				}else{
					alert('操作失败');
				}

			},'json');

		});


	});


	function uploadeImage(ele,i) {


		var selected_file =  ele.files[0];
		var filename=  selected_file.name;
		filename = filename.replace("&","");
		filename = filename.replace("_","");
		var url =  '/?/account/ajax/cert_photo_upload/type'+'-'+'user_cert_photo__is_back' + '-' + i + '__upload_file'+'-' + filename+ '__timestamp'+'-' + new Date().getTime();


		do_upload(url, selected_file, function(result){
			   var attach_url = result.url;

				right_img = attach_url;
				//$("#right_img").attr("src", attach_url);
				$("#right_img").attr("src", getObjectURL(selected_file));



			// window.location.reload();
		});

	}




	function do_upload(url, file, callback)
	{
		var xhr = new XMLHttpRequest();
		xhr.open('POST', url, true);
		xhr.onload = function(e) {
		};

		xhr.onreadystatechange = function() {

			if (xhr.readyState == 4 && xhr.status == 200) {
				try {
					responseData = $.parseJSON(xhr.responseText);
					if (responseData.errno == 1) {
						callback(responseData.rsm);
					} else {
						alert(responseData.err);
					}
				} catch(err) {
					response = {};
				}
			}
		};
		xhr.send(file);
	}


	function ajaxUpload(ele) {


		var selected_file =  ele.files[0];

		jQuery.ajaxFileUpload({
			url : '/account/ajax/avatar_upload/', //用于文件上传的服务器端请求地址
			secureuri : false, //是否需要安全协议，一般设置为false
			fileElementId :"file_form", //文件上传域的ID
			dataType : 'json', //返回值类型 一般设置为json
			success : function(data, status)//服务器成功响应处理函数
			{
				if(data.success ==true){

					//$("#img_upload").attr("src", data.thumb);
					$("#img_upload").attr("src", getObjectURL(selected_file));

				}else{

					alert(data.error);
				}

			}

		});

		return false;
	};

	function getObjectURL(file) {
		var url = null;
		if (window.createObjectURL != undefined) { // basic
			url = window.createObjectURL(file);
		} else if (window.URL != undefined) { // mozilla(firefox)
			url = window.URL.createObjectURL(file);
		} else if (window.webkitURL != undefined) { // webkit or chrome
			url = window.webkitURL.createObjectURL(file);
		}
		return url;
	}

</script>